package shun.demo.remote.touch.server;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.text.format.Formatter;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import shun.demo.R;

import java.net.InetAddress;

/**
 * Created by chen on 14-4-26.
 */
public class ServerActivity extends Activity implements View.OnClickListener {

    private InputServer mInputServer;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.input_server);
        mInputServer = new InputServer();
        initAddress();
    }

    private void initAddress() {
        WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wm.getConnectionInfo();
        if (wifiInfo != null) {
            int ip = wifiInfo.getIpAddress();
            String ipString = Formatter.formatIpAddress(ip);
            TextView textView = (TextView) findViewById(R.id.address);
            textView.setText(ipString);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.start:
                mInputServer.start();
                break;
            case R.id.stop:
                mInputServer.stop();
                break;
        }
    }
}
